
using Newtonsoft.Json;
using System;
using UnityEngine;

namespace Client.Hotfix
{
    public abstract class CWebApi
    {
        public readonly string api;
        public CWebRequestData body;
        public CWebApi()
        {
            var attribute = (APIAttribute)Attribute.GetCustomAttribute(GetType(), typeof(APIAttribute));
            if (attribute != null)
            {
                api = attribute.api;
            }
            else
            {
                Debug.Log($"{GetType().Name} APIAttribute is null!");
            }
        }
        public T Parse<T>(string jsonData) where T : CWebResponeData
        {
             return JsonConvert.DeserializeObject<T>(jsonData);
        }
  

        public override string ToString()
        {
            if (string.IsNullOrEmpty(api))
            {
                return $"{GetType().Name} api is null!";
            }
            else if (this.body == null)
            {
                return $"{GetType().Name} body is null!";
            }
            else
            {
                return $" {api} --> {body.ToString()} ";
            }
        }
    }
}

